From c35b82a036e9e819accb8eeba2a9648de8afdaa9 Mon Sep 17 00:00:00 2001 From: Alexandre Emsenhuber Date: Tue, 15 Nov 2011 18:08:34 +0000 Subject: [PATCH] * Factorise common code in ImagePage::delete() and allow normal page deletion if $wgUploadMaintenance is true * Moved $wgUploadMaintenance check after permissions and read only, so that the user doesn't think the error is temporary if he both doesn't have the permission and $wgUploadMaintenance is true * Show normal error page when $wgUploadMaintenance and added a message for the error title * Moved watchlist updating to FileDeletForm::execute(), it has nothing to do in doDelete() (would also be executed for api requests, etc.) * Added $user parameter to FileDeletForm::doDelete() to pass the user doing the action * Use WikiPage instead of Article --- docs/hooks.txt | 2 +- includes/FileDeleteForm.php | 43 +++++++++++++++++++----------- includes/ImagePage.php | 12 +++------ languages/messages/MessagesEn.php | 31 ++++++++++----------- languages/messages/MessagesQqq.php | 20 +++++++------- maintenance/language/messages.inc | 1 + 6 files changed, 60 insertions(+), 49 deletions(-) diff --git a/docs/hooks.txt b/docs/hooks.txt index 9ff4bdad72..3536c35029 100644 --- a/docs/hooks.txt +++ b/docs/hooks.txt @@ -874,7 +874,7 @@ $user: User the list is being fetched for $file: reference to the deleted file $oldimage: in case of the deletion of an old image, the name of the old file $article: in case all revisions of the file are deleted a reference to the - article associated with the file. + WikiFilePage associated with the file. $user: user who performed the deletion $reason: reason diff --git a/includes/FileDeleteForm.php b/includes/FileDeleteForm.php index 900b7d9535..a5282139ce 100644 --- a/includes/FileDeleteForm.php +++ b/includes/FileDeleteForm.php @@ -39,7 +39,7 @@ class FileDeleteForm { * pending authentication, confirmation, etc. */ public function execute() { - global $wgOut, $wgRequest, $wgUser; + global $wgOut, $wgRequest, $wgUser, $wgUploadMaintenance; $permissionErrors = $this->title->getUserPermissionsErrors( 'delete', $wgUser ); if ( count( $permissionErrors ) ) { @@ -50,6 +50,10 @@ class FileDeleteForm { throw new ReadOnlyError; } + if ( $wgUploadMaintenance ) { + throw new ErrorPageError( 'filedelete-maintenance-title', 'filedelete-maintenance' ); + } + $this->setHeaders(); $this->oldimage = $wgRequest->getText( 'oldimage', false ); @@ -81,7 +85,7 @@ class FileDeleteForm { $reason = $deleteReasonList; } - $status = self::doDelete( $this->title, $this->file, $this->oldimage, $reason, $suppress ); + $status = self::doDelete( $this->title, $this->file, $this->oldimage, $reason, $suppress, $wgUser ); if( !$status->isGood() ) { $wgOut->addHTML( '

' . $this->prepareMessage( 'filedeleteerror-short' ) . "

\n" ); @@ -95,6 +99,12 @@ class FileDeleteForm { // Return to the main page if we just deleted all versions of the // file, otherwise go back to the description page $wgOut->addReturnTo( $this->oldimage ? $this->title : Title::newMainPage() ); + + if ( $wgRequest->getCheck( 'wpWatch' ) && $wgUser->isLoggedIn() ) { + WatchAction::doWatch( $title, $wgUser ); + } elseif ( $this->title->userIsWatching() ) { + WatchAction::doUnwatch( $title, $wgUser ); + } } return; } @@ -111,13 +121,16 @@ class FileDeleteForm { * @param $oldimage String: archive name * @param $reason String: reason of the deletion * @param $suppress Boolean: whether to mark all deleted versions as restricted + * @param $user User object performing the request */ - public static function doDelete( &$title, &$file, &$oldimage, $reason, $suppress ) { - global $wgUser; - $article = null; - $status = Status::newFatal( 'error' ); + public static function doDelete( &$title, &$file, &$oldimage, $reason, $suppress, User $user = null ) { + if ( $user === null ) { + global $wgUser; + $user = $wgUser; + } if( $oldimage ) { + $page = null; $status = $file->deleteOld( $oldimage, $reason, $suppress ); if( $status->ok ) { // Need to do a log item @@ -129,18 +142,14 @@ class FileDeleteForm { $log->addEntry( 'delete', $title, $logComment ); } } else { + $status = Status::newFatal( 'error' ); $id = $title->getArticleID( Title::GAID_FOR_UPDATE ); - $article = new Article( $title ); + $page = WikiPage::factory( $title ); $dbw = wfGetDB( DB_MASTER ); try { // delete the associated article first - if( $article->doDeleteArticle( $reason, $suppress, $id, false ) ) { - global $wgRequest; - if ( $wgRequest->getCheck( 'wpWatch' ) && $wgUser->isLoggedIn() ) { - WatchAction::doWatch( $title, $wgUser ); - } elseif ( $title->userIsWatching() ) { - WatchAction::doUnwatch( $title, $wgUser ); - } + $error = ''; + if ( $page->doDeleteArticle( $reason, $suppress, $id, false, $error, $user ) ) { $status = $file->delete( $reason, $suppress ); if( $status->ok ) { $dbw->commit(); @@ -154,8 +163,10 @@ class FileDeleteForm { throw $e; } } - if( $status->isGood() ) - wfRunHooks('FileDeleteComplete', array( &$file, &$oldimage, &$article, &$wgUser, &$reason)); + + if ( $status->isGood() ) { + wfRunHooks( 'FileDeleteComplete', array( &$file, &$oldimage, &$page, &$user, &$reason ) ); + } return $status; } diff --git a/includes/ImagePage.php b/includes/ImagePage.php index 0bed464a71..f9aab29e60 100644 --- a/includes/ImagePage.php +++ b/includes/ImagePage.php @@ -789,19 +789,15 @@ EOT */ public function delete() { global $wgUploadMaintenance; - if ( $wgUploadMaintenance && $this->getTitle() && $this->getTitle()->getNamespace() == NS_FILE ) { - global $wgOut; - $wgOut->wrapWikiMsg( "
\n$1\n
\n", array( 'filedelete-maintenance' ) ); - return; - } - $this->loadFile(); - if ( !$this->mPage->getFile()->exists() || !$this->mPage->getFile()->isLocal() || $this->mPage->getFile()->getRedirected() ) { + $file = $this->mPage->getFile(); + if ( !$file->exists() || !$file->isLocal() || $file->getRedirected() ) { // Standard article deletion parent::delete(); return; } - $deleter = new FileDeleteForm( $this->mPage->getFile() ); + + $deleter = new FileDeleteForm( $file ); $deleter->execute(); } diff --git a/languages/messages/MessagesEn.php b/languages/messages/MessagesEn.php index 79105defa0..79f7dee1b2 100644 --- a/languages/messages/MessagesEn.php +++ b/languages/messages/MessagesEn.php @@ -2365,23 +2365,24 @@ The description on its [$2 file description page] there is shown below.', 'filerevert-badversion' => 'There is no previous local version of this file with the provided timestamp.', # File deletion -'filedelete' => 'Delete $1', -'filedelete-legend' => 'Delete file', -'filedelete-intro' => "You are about to delete the file '''[[Media:$1|$1]]''' along with all of its history.", -'filedelete-intro-old' => "You are deleting the version of '''[[Media:$1|$1]]''' as of [$4 $3, $2].", -'filedelete-comment' => 'Reason:', -'filedelete-submit' => 'Delete', -'filedelete-success' => "'''$1''' has been deleted.", -'filedelete-success-old' => "The version of '''[[Media:$1|$1]]''' as of $3, $2 has been deleted.", -'filedelete-nofile' => "'''$1''' does not exist.", -'filedelete-nofile-old' => "There is no archived version of '''$1''' with the specified attributes.", -'filedelete-otherreason' => 'Other/additional reason:', -'filedelete-reason-otherlist' => 'Other reason', -'filedelete-reason-dropdown' => '*Common delete reasons +'filedelete' => 'Delete $1', +'filedelete-legend' => 'Delete file', +'filedelete-intro' => "You are about to delete the file '''[[Media:$1|$1]]''' along with all of its history.", +'filedelete-intro-old' => "You are deleting the version of '''[[Media:$1|$1]]''' as of [$4 $3, $2].", +'filedelete-comment' => 'Reason:', +'filedelete-submit' => 'Delete', +'filedelete-success' => "'''$1''' has been deleted.", +'filedelete-success-old' => "The version of '''[[Media:$1|$1]]''' as of $3, $2 has been deleted.", +'filedelete-nofile' => "'''$1''' does not exist.", +'filedelete-nofile-old' => "There is no archived version of '''$1''' with the specified attributes.", +'filedelete-otherreason' => 'Other/additional reason:', +'filedelete-reason-otherlist' => 'Other reason', +'filedelete-reason-dropdown' => '*Common delete reasons ** Copyright violation ** Duplicated file', -'filedelete-edit-reasonlist' => 'Edit delete reasons', -'filedelete-maintenance' => 'Deletion and restoration of files temporarily disabled during maintenance.', +'filedelete-edit-reasonlist' => 'Edit delete reasons', +'filedelete-maintenance' => 'Deletion and restoration of files temporarily disabled during maintenance.', +'filedelete-maintenance-title' => 'Cannot delete file', # MIME search 'mimesearch' => 'MIME search', diff --git a/languages/messages/MessagesQqq.php b/languages/messages/MessagesQqq.php index 7588e2e529..f27a885dc7 100644 --- a/languages/messages/MessagesQqq.php +++ b/languages/messages/MessagesQqq.php @@ -2015,30 +2015,32 @@ $1 is the name of the shared repository. On wikimedia sites, $1 is {{msg-mw|shar {{Identical|Revert}}', # File deletion -'filedelete-legend' => '{{Identical|Delete}}', -'filedelete-intro-old' => 'Message displayed when you try to delete a version of a file. +'filedelete-legend' => '{{Identical|Delete}}', +'filedelete-intro-old' => 'Message displayed when you try to delete a version of a file. * $1 is the name of the media * $2 is a date * $3 is a hour * $4 is a URL and must follow square bracket: [$4', -'filedelete-comment' => '{{Identical|Reason}}', -'filedelete-submit' => 'Delete button when deleting a file for admins +'filedelete-comment' => '{{Identical|Reason}}', +'filedelete-submit' => 'Delete button when deleting a file for admins {{Identical|Delete}}', -'filedelete-success-old' => 'Message displayed when you succeed in deleting a version of a file. +'filedelete-success-old' => 'Message displayed when you succeed in deleting a version of a file. * $1 is the name of the media * $2 is a date * $3 is a hour', -'filedelete-otherreason' => 'Message used when deleting a file. This is the description field for "Other/additional reason" for deletion. +'filedelete-otherreason' => 'Message used when deleting a file. This is the description field for "Other/additional reason" for deletion. {{Identical|Other/additional reason}}', -'filedelete-reason-otherlist' => 'Message used as default in the dropdown menu in the form for deleting a file. Keeping this message selected assumes that a reason for deletion is specified in the field below. +'filedelete-reason-otherlist' => 'Message used as default in the dropdown menu in the form for deleting a file. Keeping this message selected assumes that a reason for deletion is specified in the field below. {{Identical|Other reason}}', -'filedelete-reason-dropdown' => 'Predefined reasons for deleting a file that can be selected in a drop down list. Entries prefixed with one asterisk ("*") are group headers and cannot be selected. Entries prefixed with two asterisks can be selected as reason for deletion.', -'filedelete-edit-reasonlist' => 'Shown beneath the file deletion form on the right side. It is a link to [[MediaWiki:Filedelete-reason-dropdown]]. +'filedelete-reason-dropdown' => 'Predefined reasons for deleting a file that can be selected in a drop down list. Entries prefixed with one asterisk ("*") are group headers and cannot be selected. Entries prefixed with two asterisks can be selected as reason for deletion.', +'filedelete-edit-reasonlist' => 'Shown beneath the file deletion form on the right side. It is a link to [[MediaWiki:Filedelete-reason-dropdown]]. {{Identical|Edit delete reasons}}', +'filedelete-maintenance' => 'Content of the error page when $wgUploadMaintenance is set to true.', +'filedelete-maintenance-title' => 'Title of the error page when $wgUploadMaintenance is set to true.', # MIME search 'mimesearch' => 'Title of [[Special:MIMESearch]].', diff --git a/maintenance/language/messages.inc b/maintenance/language/messages.inc index 42fd76bc76..71b099510a 100644 --- a/maintenance/language/messages.inc +++ b/maintenance/language/messages.inc @@ -1481,6 +1481,7 @@ $wgMessageStructure = array( 'filedelete-reason-dropdown', 'filedelete-edit-reasonlist', 'filedelete-maintenance', + 'filedelete-maintenance-title', ), 'mimesearch' => array( 'mimesearch', -- 2.20.1